// cf-95b
// run: $exec < input
#include <iostream>
#include <string>

std::string s;
std::string ans;
int n;

void find4_replace7(int c4, int c7, int i)
{
	int j = i - 1;
	for (; j >= 0; j--)
		if (ans[j] == '7') c7++;
		else { c4++; if (c7) break; }
	if (j == -1)
		ans = std::string(n / 2 + 1, '4') + std::string(n / 2 + 1, '7');
	else {
		ans[j] = '7';
		c7--;
		for (int tj = 0; tj < c4; tj++) ans[j + tj + 1] = '4';
		for (int tj = j + 1 + c4; tj < n; tj++) ans[tj] = '7';
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> s;
	n = s.size();
	ans.resize(n);
	if (n & 1) {
		n++;
		std::cout << std::string(n / 2, '4') + std::string(n / 2, '7');
		return 0;
	}
	int c4 = n / 2, c7 = n / 2, last4 = -1, last7 = -1;
	for (int i = 0; i < n; i++) {
		if (s[i] < '4') {
			for (int j = 0; j < c4; j++) ans[i + j] = '4';
			for (int j = i + c4; j < n; j++) ans[j] = '7';
			break;
		} else if (s[i] == '4') {
			if (!c4) {
				for (int j = i; j < n; j++) ans[i] = '7';
				break;
			}
			ans[i] = '4';
			last4 = i;
			c4--;
		} else if (s[i] < '7') {
			if (c7) {
				if (!c7) { find4_replace7(c4, c7, i); break; }
				ans[i] = '7';
				c7--;
				for (int j = 0; j < c4; j++) ans[i + 1 + j] = '4';
				for (int j = i + 1 + c4; j < n; j++) ans[j] = '7';
			} else
				find4_replace7(c4, c7, i);
			break;
		} else if (s[i] == '7') {
			if (!c7) { find4_replace7(c4, c7, i); break; }
			ans[i] = '7';
			last7 = i;
			c7--;
		} else {
			find4_replace7(c4, c7, i);
			break;
		}
	}
	std::cout << ans << '\n';
}

